/*
 * Wazuh Vulnerability Scanner - Unit Tests
 * Copyright (C) 2015, Wazuh Inc.
 * February 21, 2024.
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License (version 2) as published by the FSF - Free Software
 * Foundation.
 */

#ifndef _QUERY_ALL_PACKAGES_TEST_HPP
#define _QUERY_ALL_PACKAGES_TEST_HPP

// databaseFeedManager.hpp should be included before its mock due to
// the declaración of FlatbufferDataPair.
#include "databaseFeedManager.hpp"
#include "socketServer.hpp"
#include "gtest/gtest.h"

const std::filesystem::path TEST_DB_PATH {std::filesystem::current_path() / "queue/db"};
const std::filesystem::path TEST_SOCKET_PATH {TEST_DB_PATH / "wdb"};
const std::filesystem::path INVENTORY_DB_PATH {"queue/vd/inventory"};

/**
 * @brief QueryAllPackages test class.
 *
 */
class QueryAllPackagesTest : public ::testing::Test
{
protected:
    // LCOV_EXCL_START
    QueryAllPackagesTest() = default;
    ~QueryAllPackagesTest() override = default;

    /**
     * @brief Set the environment for testing.
     *
     */
    void SetUp() override
    {
        m_inventoryDatabase = std::make_unique<Utils::RocksDBWrapper>(INVENTORY_DB_PATH);

        std::filesystem::create_directories(TEST_DB_PATH);
        m_socketServer =
            std::make_shared<SocketServer<Socket<OSPrimitives, SizeHeaderProtocol>, EpollWrapper>>(TEST_SOCKET_PATH);
    }

    /**
     * @brief Clean the environment after testing.
     *
     */
    void TearDown() override
    {
        std::filesystem::remove_all("queue");
        m_socketServer.reset();
    }

    /**
     * @brief Fake server socket.
     */
    std::shared_ptr<SocketServer<Socket<OSPrimitives, SizeHeaderProtocol>, EpollWrapper>> m_socketServer;

    /**
     * @brief RocksDB inventory database.
     *
     */
    std::unique_ptr<Utils::RocksDBWrapper> m_inventoryDatabase;
    // LCOV_EXCL_STOP
};

#endif // _QUERY_ALL_PACKAGES_TEST_HPP
